import {
  HashRouter as Router,
  Redirect,
  Route,
  Switch,
} from "react-router-dom";
import FileUpload from "./page/FileUpload";
import QRCode from "./page/QRCodeGenerate";
import QRCodePreview from "./page/QRCodePreview";

const routes: any = [
  { path: "/create", exact: true, Component: QRCode },
  { path: "/preview/:id", exact: false, Component: QRCodePreview },
  { path: "/fileUpload", exact: true, Component: FileUpload },
];

const renderRoute = (route: any) => {
  const { path, exact, Component } = route;
  return <Route key={path} exact={exact} path={path} component={Component} />;
};

function App() {
  return (
    <Router>
      <Switch>
        {routes.map(renderRoute)}
        <Redirect from="/" to="/create" />
      </Switch>
    </Router>
  );
}

export default App;
